package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_UNION_CHANGE_FLAG, desc = "修改联盟旗帜")
public class CrossChangeUnionFlagCmd extends CrossCommand {

    long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        UnionProto.UnionModifyFlagReqMsg reqMsg = UnionProto.UnionModifyFlagReqMsg.parseFrom(packet.getBytes());
        int unionFlag = reqMsg.getUnionFlag();

        ret = CrossUnionMgr.changeUnionFlag(serverId, packet.getPlayerId(), unionFlag);

    }

    @Override
    public void sendData() {
        if(ret != 0){
            UnionProto.UnionChangeRandomJoinRespMsg.Builder respMsg = UnionProto.UnionChangeRandomJoinRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_UNION_CHANGE_FLAG, respMsg));
        }
    }
}
